package com.yu.serviceImpl;

import com.yu.Dao.UserDao;
import com.yu.DaoImpl.UserDaoImpl;
import com.yu.Pojo.User;
import com.yu.service.UserService;

import java.sql.SQLException;

//service无实际意义 起一个传话的功能 来调用UserDao
public class UserServiceImpl implements UserService {


    public int addUser(User user) throws Exception {
        //先调用其他 方法查询用户是否存在
       User user1 = findUserByName (user.getUserName ());
       if(user1 != null){
           return 0;
       }
        UserDao userDao = new UserDaoImpl();
        //表示插入了几条数据
       int i =  userDao.insertUser(user);
        return i;
    }

    public User findUserByName (String username) throws SQLException, ClassNotFoundException {
        UserDao userDao = new UserDaoImpl();
        User user = userDao.selectByName (username);

        return user;
    }

    public User findUser (User user) throws SQLException, ClassNotFoundException {
        UserDao userDao = new UserDaoImpl();

        User user1 = userDao.loginQuery(user);

        return user1;
    }
}
